﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnyRepMembershipProvider;

namespace AnyRepMembershipProvider.Tests.Mocks
{
    public class MockAnyRepMembershipRepository : IAnyRepMembershipRepository
    {
        List<AnyRepMembershipUser> users = new List<AnyRepMembershipUser>();

        public MockAnyRepMembershipRepository()
        {
            users.Add(new AnyRepMembershipUser() { UserId = Guid.NewGuid(), Username = "rafael", Password = "Admin@123", Email = "rafael@ravero.net", IsApproved = true, PasswordAnswer = "", PasswordQuestion = "", IsLockedOut = false, CreatedDate = DateTime.Parse("2009-05-12 15:20:00") });
            users.Add(new AnyRepMembershipUser() { UserId = Guid.NewGuid(), Username = "paulo", Password = "Trocar@123", Email = "paulo@improversoftware.com", IsApproved = true, PasswordAnswer = "", PasswordQuestion = "", IsLockedOut = false, CreatedDate = DateTime.Parse("2011-01-21 09:50:00") });
            users.Add(new AnyRepMembershipUser() { UserId = Guid.NewGuid(), Username = "zezinho", Password = "Ze$inh0", Email = "zezinho@hotmail.com", IsApproved = true, PasswordAnswer = "", PasswordQuestion = "", IsLockedOut = false, CreatedDate = DateTime.Parse("2010-09-18 22:32:00") });
        }

        private string _applicationName;
        public string ApplicationName
        {
            get { return _applicationName; }
            set { _applicationName = value; }
        }

        public void AddUser(AnyRepMembershipUser user)
        {
            throw new NotImplementedException();
        }

        public AnyRepMembershipUser GetUserById(Guid userId)
        {
            throw new NotImplementedException();
        }

        public AnyRepMembershipUser GetUserByUsername(string userName)
        {
            return users.FirstOrDefault(u => u.Username == userName);
        }

        public AnyRepMembershipUser GetUserByEmail(string email)
        {
            return users.FirstOrDefault(u => u.Email == email);
        }

        public void UpdateUserLastActivity(AnyRepMembershipUser user)
        {
            var storageUser = users.FirstOrDefault(u => u.UserId == user.UserId);
            if (storageUser != null)
            {
                storageUser.LastLockoutDate = DateTime.Now;
            }
        }
    }
}
